// pages/table1/table1.js
const network = require('../../../../utils/network.js')
var app = getApp();
var pageSize = 0;
var startTime_n, endTime_n, dept_n, type_n, deptName_n;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    headers: [{ text: 'itemId', display: '排名' }, { text: 'itemCode', display: '代码' }, { text: 'itemName', display: '项目' }, { text: 'quantity', display: '数量' }, { text: 'price', display: '单价' }, { text: 'amount', display: '金额' }],
    row: [],
    current: 1,
    totalPage: 1,
    typeName:"",
    deptName:"",
    isDisabled_ch: false,
    isDisabled_as: false
  },
  onChange(e) {
    console.log('onChange', e)
    this.setData({
      current: e.detail.current,
    })

    this.myRequest(e)
  },

  myRequest: function (options) {
    var that = this;
    //console.log('options:', options)
    //获得表格高度
    var windowheight = wx.getSystemInfoSync().windowHeight;
    var tdHeight = [18.4, 21.6, 39]
    if (windowheight < 550) {
      pageSize = Math.round(windowheight * 0.8 / tdHeight[0]);
    } else if (windowheight < 850) {
      pageSize = Math.round(windowheight * 0.8 / tdHeight[1]);
    } else {
      pageSize = Math.round(windowheight * 0.8 / tdHeight[2]);
    }
    console.log("每页个数", pageSize);
    //调用封装好的网络请求，获取数据
    network.get('/mt/detail?startTime=' + startTime_n + '&endTime=' + endTime_n + '&dept=' + dept_n + '&type=' + type_n+ '&pageCount=' + that.data.current + '&pageSize=' + pageSize, {}).then(function (res) {
      console.log('res:', res)
      var typeName_n, typeBtn_ch_n, typeBtn_as_n, isDisabled_ch_n, isDisabled_as_n;
      console.log(type_n == "6")
      if (type_n == "6"){
        typeName_n = "检查";
        
        isDisabled_ch_n = true
        isDisabled_as_n = false
      } else if (type_n == "7"){
        typeName_n = "化验";
        
        isDisabled_ch_n = false
        isDisabled_as_n = true
      }
      that.setData({
        startTime: startTime_n,
        endTime: endTime_n,
        typeName: typeName_n,
        deptName: deptName_n,
        isDisabled_ch: isDisabled_ch_n,
        isDisabled_as: isDisabled_as_n,
        msg: res.data.errMsg,
        row: res.data.data,
        totalPage: res.data.totalPage

      })
      console.log('row:', that.data.row)

    }).then(function (res) {
      wx.hideLoading()
      //that.createColumnChart();

    }).catch(function (res) {
      console.log(res)
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    wx.showLoading({
      title: '加载中',
    })
    startTime_n = options.startTime
    endTime_n = options.endTime
    dept_n = options.dept
    deptName_n = options.deptName
    type_n = options.type
    that.myRequest(options)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  onclickCheck: function (e){
    type_n = "6"
    this.myRequest(e)
  },
  onclickAssay: function (e) {
    type_n = "7"
    this.myRequest(e)
  }

})